package ca.etsmtl.log660.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;

import ca.etsmtl.log660.entity.Personne;
import ca.etsmtl.log660.servlet.Controler;

public class DetailPersonne extends JPanel{

	private JTextArea biographieField;
	private JTextField nomField;
	private JTextField naissanceField;
	private JTextField lieuField;
	private DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
	
	private static final long serialVersionUID = 1L;

	public DetailPersonne(){
JLabel lblLogin = new JLabel("Lieu naissance:");
		
		JLabel lblPays = new JLabel("Biographie:");
		
		biographieField = new JTextArea(10,25);
		biographieField.setColumns(25);
		biographieField.setLineWrap(true);
		biographieField.setEditable(false);
		
		JScrollPane jScrollPaneBio = new JScrollPane(biographieField);
		
		JLabel titreLabel = new JLabel("Nom complet:");
		
		JLabel realisateurLabel = new JLabel("Naissance:");
		
		nomField = new JTextField();
		nomField.setColumns(25);
		nomField.setEditable(false);
		
		naissanceField = new JTextField();
		naissanceField.setColumns(25);
		naissanceField.setEditable(false);
		
		lieuField = new JTextField();
		lieuField.setColumns(25);
		lieuField.setEditable(false);
		
		JButton okButton = new JButton("Retour");
		okButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				retourBoutonAction();
			}
		});
		
		GroupLayout gl_panel = new GroupLayout(this);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addGap(71)
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING, false)
						.addComponent(titreLabel)
						.addComponent(realisateurLabel)
						.addComponent(lblLogin, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(lblPays, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
					.addGap(61)
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addComponent(okButton)
						.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING, false)
							.addComponent(lieuField, Alignment.LEADING)
							.addComponent(naissanceField)
							.addComponent(nomField, Alignment.LEADING))
							.addComponent(jScrollPaneBio, Alignment.LEADING))
					.addContainerGap(129, Short.MAX_VALUE))
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
						.addGap(18)
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(titreLabel)
						.addComponent(nomField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(realisateurLabel)
						.addComponent(naissanceField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblLogin)
						.addComponent(lieuField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(ComponentPlacement.RELATED)
						.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblPays)
						.addComponent(jScrollPaneBio, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(50)
					.addComponent(okButton)
					.addContainerGap(52, Short.MAX_VALUE))
		);
		this.setLayout(gl_panel);
	}
	
	public void RemplirChamps(Personne personne){
		nomField.setText(personne.getNom());
		naissanceField.setText(df.format(personne.getNaissance()));
		lieuField.setText(personne.getLieuNaissance());
		biographieField.setText(personne.getBiographie());
	}
	
	public void retourBoutonAction(){
		Controler.getControler().getSysteme().retourFilm();
	}
}
